package org.example.ttms.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import org.example.ttms.customize.Pop_ups;
import org.example.ttms.entityClass.train.Station;

import java.util.HashMap;
import java.util.Map;

public class AddStationController {

    @FXML
    private StackPane stackPane;

    @FXML
    private TextField textField;

    @FXML
    private Button addButton;

    //添加站台评判
    public boolean addStationJudgement(String name){
        Station station = new Station();
        HashMap<String, Station> hashMap = station.obtainAllStation();
        for(Map.Entry<String, Station> map : hashMap.entrySet()){
            if(map.getKey().equals(name)){
                Pop_ups popUps = new Pop_ups();
                popUps.pop_ups3("站点已存在");
                return false;
            }
        }
        return true;
    }
    @FXML
    void chickAdd(ActionEvent event) {
        if(!addStationJudgement(textField.getText()))
            return ;
        Station station = new Station(textField.getText(), 0);
        station.addStation(station);
        textField.setText("");
        Pop_ups popUps = new Pop_ups();
        popUps.pop_ups4("添加成功");
    }

}
